        package DAL;

        import java.util.*;
        
        import DBUtil.SQLUtil;
        
        public class Partment {
        	

		//获取部门表信息列表
		public List<Object> getEntity()
		{
			String sqlCmd="select *from Partment";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
            
               //获取分页后部门表信息列表
		public List<Object> getEntity(int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from Partment limit "+size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
                
               //根据查询条件sqlWhere获取分页后部门表信息列表
		public List<Object> getEntityByWhere(String sqlWhere,int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from Partment where "+sqlWhere+" limit "+ size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
                }
                
                //删除部门表信息
                public int deleteEntity(String PId)
                {
                    String sqlCmd="delete from Partment where PId='"+PId+"'";
                    return DBUtil.SQLUtil.executeNonQuery(sqlCmd, null);//执行非查询操作executeNonQuery
                }
                
                //根据部门表编号获取部门表信息
                public List<Object> getEntityById(String PId)
                {
                    String sqlCmd="select *From Partment where PId='"+PId+"'";
                    return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
                }
                
                //更新部门表信息
                public int updateEntity(String PId,String PName,String PLeader)
                {
                    String sqlCmd="Update Partment set PName='" + PName + "',PLeader='" + PLeader + "' where PId='"+PId+"'";
                    return SQLUtil.executeNonQuery(sqlCmd, null);
                }
                public int updateEntity(String PId,String Pscore)
                {
                    String sqlCmd="Update Partment set Pscore='" + Pscore + "' where PId='"+PId+"'";
                    return SQLUtil.executeNonQuery(sqlCmd, null);
                }
                
                //插入部门表信息
                public int insertEntity(String PId,String PName,String PLeader)
                {
                    String sqlCmd="Insert into Partment values('" + PId + "','" + PName + "','"+PLeader+"')";
                    return SQLUtil.executeNonQuery(sqlCmd, null);
                }
                
                //检查插入主键是否重复
                public boolean checkExist(String PId)
                {
                    String sqlCmd="select count(*) from Partment where PId='"+PId+"'";
                    if(1==Integer.parseInt(SQLUtil.excuteScalar(sqlCmd, null).toString()) )
                    {
                        return true;
                    }
                    return false;
                }

		//获取分页总数
		public Object getPageCount()
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM Partment ";
			return SQLUtil.excuteScalar(sqlCmd, null);
		}

		//根据查询条件获取分页总数
		public Object getPageCountByWhere(String sqlWhere)
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM Partment where "+sqlWhere;
			return SQLUtil.excuteScalar(sqlCmd, null);
		}
            
        }
